/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db_interaction;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Session;

/**
 *
 * @author Neves
 */
@Entity
@Table(name = "Ranking_desc")
public class Ranking_desc implements Serializable {

    @Id
    @GeneratedValue
    private int Ranking_desc_id;
    @Basic
    @Column(name = "Ranking_desc_descricao")
    private String Ranking_desc_descricao;
    @Basic
    @Column(name = "Ranking_desc_activo")
    private boolean Ranking_desc_activo;

    //GETS
    public int GETRanking_desc_id() {
        return this.Ranking_desc_id;
    }

    public String GETRanking_desc_descricao() {
        return this.Ranking_desc_descricao;
    }

    public boolean GETRanking_desc_activo() {
        return this.Ranking_desc_activo;
    }

    //SETS
    public void SETRanking_desc_id(int Ranking_desc_id) {
        this.Ranking_desc_id = Ranking_desc_id;
    }

    public void SETRanking_desc_descricao(String Ranking_desc_descricao) {
        this.Ranking_desc_descricao = Ranking_desc_descricao;
    }

    public void SETRanking_desc_desc_activo(boolean Ranking_desc_activo) {
        this.Ranking_desc_activo = Ranking_desc_activo;
    }

    //DB access
    public int insertEntity(Ranking_desc rkdesc) {
        //returns 1 if successfull
        //return -1 if error
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            s.save(rkdesc);
            s.getTransaction().commit();
            System.out.println("Inserido");
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    public Ranking_desc SelectEntity(Ranking_desc rkdesc) {
        Ranking_desc rankingDesc = null;

        //returns sellected friend if successfull
        //return null
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            rankingDesc = (Ranking_desc) s.load(Ranking_desc.class, rkdesc.GETRanking_desc_id());
            s.getTransaction().commit();
            return rankingDesc;

        } catch (Exception e) {
            return rankingDesc;
        }
    }

    public int UpdateEntity(Ranking_desc rkdesc) {
        //returns 1 if successfull
        //return -1 if error
        try {
            Session s = NewHibernateUtil.getSessionFactory();
            s.save(rkdesc);
            s.getTransaction().commit();
            return 1;

        } catch (Exception e) {
            return -1;
        }
    }
}
